package ch.sfug.anim.tween.filter {
	import flash.display.DisplayObject;
	import flash.filters.BlurFilter;
	
	import ch.sfug.anim.tween.filter.AbstractFilterTween;
	import ch.sfug.anim.tween.property.PropertyTween;
	
	import flash.filters.BitmapFilter;		

	/**
	 * this is a tween that animates the properties of the blurfilter.
	 * 
	 * @author mich
	 */
	public class BlurTween extends AbstractFilterTween {

		public function BlurTween( dis:DisplayObject, d:Number ) {
			super(dis, d);
		}

		protected override function getClass():Class {
			return BlurFilter;
		}

		protected override function shouldBeApplied():Boolean {
			var bf:BlurFilter = BlurFilter(filter);
			return bf.blurX != 0 && bf.blurY != 0;
		}

		protected override function defaultFilter():BitmapFilter {
			return new BlurFilter();
		}

		/**
		 * blurs the displayobject to a new blur value
		 */
		public function blurTo( xblur:Number, yblur:Number, easeBoth:Function = null, easeY:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(xblur) ) obj.blurX = { to: xblur, easing:easeBoth };
			if( !isNaN(yblur) ) obj.blurY = { to: yblur, easing:( easeY == null ) ? easeBoth : easeY };
			tweenFilter(obj);
		}
		
		/**
		 * tweens the strength value.
		 */
		public function strengthTo( s:Number, ease:Function = null ):void {
			var obj:Object = new Object();
			obj.strength = { to:s, easing:ease };
			tweenFilter(obj);
		}
		
		public function apply( blurX:Number = NaN, blurY:Number = NaN, quality:Number = NaN ):void {
			var bf:BlurFilter = BlurFilter( filter );
			if( !isNaN( blurX ) ) bf.blurX = blurX;
			if( !isNaN( blurY ) ) bf.blurY = blurY;
			if( !isNaN( quality ) ) bf.quality = quality;
			super.updateFilters();
		}
	}
}
